{% set sanitizedArchitecture = dictionary['CPUs'][0]['compatible'][1].rpartition(',')[2] | upper | sanitize('[^0-9A-Za-z]') %}
{% set sanitizedCpu = dictionary['CPUs'][0]['compatible'][0] | replace('+', 'plus') | upper | sanitize('[^0-9A-Za-z]') %}
#
# file: {{ metadata[metadataIndex][2] }}
#
# author: Copyright (C) 2018-2024 Kamil Szczygiel https://distortec.com https://freddiechopin.info
#
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not
# distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
#
# Automatically generated file - do not edit!
#

set(DISTORTOS_RAW_LINKER_SCRIPT "{{ outputPath }}/{{ sanitizedBoard }}.ld")

distortosSetFixedConfiguration(BOOLEAN
		DISTORTOS_ARCHITECTURE_ASCENDING_STACK
		OFF)

distortosSetFixedConfiguration(BOOLEAN
		DISTORTOS_ARCHITECTURE_EMPTY_STACK
		OFF)

distortosSetFixedConfiguration(INTEGER
		DISTORTOS_ARCHITECTURE_STACK_ALIGNMENT
		8)

distortosSetFixedConfiguration(BOOLEAN
		DISTORTOS_ARCHITECTURE_ARM
		ON)

distortosSetFixedConfiguration(BOOLEAN
		DISTORTOS_ARCHITECTURE_{{ sanitizedArchitecture }}
		ON)

distortosSetFixedConfiguration(BOOLEAN
		DISTORTOS_ARCHITECTURE_{{ sanitizedCpu }}
		ON)

distortosSetFixedConfiguration(BOOLEAN
		DISTORTOS_ARCHITECTURE_{{ sanitizedCpu }}_{{ dictionary['CPUs'][0]['revision'] | upper }}
		ON)

distortosSetConfiguration(INTEGER
		distortos_Architecture_00_Interrupt_stack_size
		1024
		MIN 8
		HELP "Size (in bytes) of \"main\" stack used by core exceptions and interrupts in Handler mode."
		OUTPUT_NAME DISTORTOS_ARCHITECTURE_MAIN_STACK_SIZE)
{% if 'ARM,ARMv7-M' in dictionary['CPUs'][0]['compatible'] or 'ARM,ARMv8-M' in dictionary['CPUs'][0]['compatible'] %}

distortosSetConfiguration(INTEGER
		distortos_Architecture_01_Interrupt_priority_disabled_in_critical_sections
		0
		MIN 0
		MAX 15
		HELP "Interrupt priority disabled in critical sections.

		Minimal numerical priority (inclusive) of interrupt handlers that can use system's functions.

		During critical sections all interrupts with numerical priority above or equal to this value will be disabled.
		Interrupts with numerical priority below this value are never disabled, but they may not use any system's
		functions.

		Note - \"lower\" logical priority has \"higher\" numeric value! If this option is set to \"x\", then interrupts
		with priorities between \"x\" and 255 (both inclusive) may use system's functions, while interrupts with
		priorities between 0 and \"x - 1\" (both inclusive) may not. If 0 is chosen, then all interrupts (except
		HardFault and NMI) are disabled during critical sections, so they may use system's functions."
		OUTPUT_NAME DISTORTOS_ARCHITECTURE_KERNEL_BASEPRI)
{% endif %}

{% set context = namespace(counter = 0) %}
distortosSetConfiguration(STRING
		distortos_Memory_regions_{{ '{:02d}'.format(context.counter) }}_text_vectorTable
{% for key, memory in dictionary['memories'].items() if memory is mapping and
	'on-chip-flash' in memory['compatible'] and '.text.vectorTable' in memory.get('sections', ['.text.vectorTable']) %}
		"{{ key }}"
{% endfor %}
		HELP "Memory region for .text.vectorTable section in linker script"
		OUTPUT_NAME DISTORTOS_LD_TEXT_VECTOR_TABLE_REGION
		OUTPUT_TYPES BOOLEAN)

{% set context.counter = context.counter + 1 %}
distortosSetConfiguration(STRING
		distortos_Memory_regions_{{ '{:02d}'.format(context.counter) }}_text
{% for key, memory in dictionary['memories'].items() if memory is mapping and
	'on-chip-flash' in memory['compatible'] and '.text' in memory.get('sections', ['.text']) %}
		"{{ key }}"
{% endfor %}
		HELP "Memory region for .text section in linker script"
		OUTPUT_NAME DISTORTOS_LD_TEXT_REGION
		OUTPUT_TYPES BOOLEAN)

{% set context.counter = context.counter + 1 %}
distortosSetConfiguration(STRING
		distortos_Memory_regions_{{ '{:02d}'.format(context.counter) }}_ARM_exidx
{% for key, memory in dictionary['memories'].items() if memory is mapping and
	'on-chip-flash' in memory['compatible'] and '.ARM.exidx' in memory.get('sections', ['.ARM.exidx']) %}
		"{{ key }}"
{% endfor %}
		HELP "Memory region for .ARM.exidx section in linker script"
		OUTPUT_NAME DISTORTOS_LD_ARM_EXIDX_REGION
		OUTPUT_TYPES BOOLEAN)

{% set context.counter = context.counter + 1 %}
distortosSetConfiguration(STRING
		distortos_Memory_regions_{{ '{:02d}'.format(context.counter) }}_Main_stack
{% for key, memory in dictionary['memories'].items() if memory is mapping and
	'on-chip-RAM' in memory['compatible'] and '.main_stack' in memory.get('sections', ['.main_stack']) %}
		"{{ key }}"
{% endfor %}
		HELP "Memory region for main stack in linker script"
		OUTPUT_NAME DISTORTOS_LD_MAIN_STACK_REGION
		OUTPUT_TYPES BOOLEAN)

{% set context.counter = context.counter + 1 %}
distortosSetConfiguration(STRING
		distortos_Memory_regions_{{ '{:02d}'.format(context.counter) }}_bss
{% for key, memory in dictionary['memories'].items() if memory is mapping and
	'on-chip-RAM' in memory['compatible'] and '.bss' in memory.get('sections', ['.bss']) %}
		"{{ key }}"
{% endfor %}
		HELP "Memory region for .bss section in linker script"
		OUTPUT_NAME DISTORTOS_LD_BSS_REGION
		OUTPUT_TYPES BOOLEAN)

{% set context.counter = context.counter + 1 %}
distortosSetConfiguration(STRING
		distortos_Memory_regions_{{ '{:02d}'.format(context.counter) }}_data_VMA
{% for key, memory in dictionary['memories'].items() if memory is mapping and
	'on-chip-RAM' in memory['compatible'] and '.data' in memory.get('sections', ['.data']) %}
		"{{ key }}"
{% endfor %}
		HELP "VMA memory region for .data section in linker script"
		OUTPUT_NAME DISTORTOS_LD_DATA_VMA_REGION
		OUTPUT_TYPES BOOLEAN)

{% set context.counter = context.counter + 1 %}
distortosSetConfiguration(STRING
		distortos_Memory_regions_{{ '{:02d}'.format(context.counter) }}_data_LMA
{% for key, memory in dictionary['memories'].items() if memory is mapping and
	'on-chip-flash' in memory['compatible'] and '.data' in memory.get('sections', ['.data']) %}
		"{{ key }}"
{% endfor %}
		HELP "LMA memory region for .data section in linker script"
		OUTPUT_NAME DISTORTOS_LD_DATA_LMA_REGION
		OUTPUT_TYPES BOOLEAN)

{% set context.counter = context.counter + 1 %}
distortosSetConfiguration(STRING
		distortos_Memory_regions_{{ '{:02d}'.format(context.counter) }}_noinit
{% for key, memory in dictionary['memories'].items() if memory is mapping and
	'on-chip-RAM' in memory['compatible'] and '.noinit' in memory.get('sections', ['.noinit']) %}
		"{{ key }}"
{% endfor %}
		HELP "Memory region for .noinit section in linker script"
		OUTPUT_NAME DISTORTOS_LD_NOINIT_REGION
		OUTPUT_TYPES BOOLEAN)
{% for ramKey, ramMemory in dictionary['memories'].items() if ramMemory is mapping and
	'on-chip-RAM' in ramMemory['compatible'] and
	'.{}.data'.format(ramKey) in ramMemory.get('sections', ['.{}.data'.format(ramKey)]) %}

{% set context.counter = context.counter + 1 %}
distortosSetConfiguration(STRING
		distortos_Memory_regions_{{ '{:02d}'.format(context.counter) }}_{{ ramKey }}_data_LMA
{% for romKey, romMemory in dictionary['memories'].items() if romMemory is mapping and
	'on-chip-flash' in romMemory['compatible'] and
	'.{}.data'.format(ramKey) in ramMemory.get('sections', ['.{}.data'.format(ramKey)]) %}
		"{{ romKey }}"
{% endfor %}
		HELP "LMA memory region for .{{ ramKey }}.data section in linker script"
		OUTPUT_NAME DISTORTOS_LD_{{ ramKey | upper }}_DATA_LMA_REGION
		OUTPUT_TYPES BOOLEAN)
{% endfor %}

{% set context.counter = context.counter + 1 %}
distortosSetConfiguration(STRING
		distortos_Memory_regions_{{ '{:02d}'.format(context.counter) }}_Process_stack
{% for key, memory in dictionary['memories'].items() if memory is mapping and
	'on-chip-RAM' in memory['compatible'] and '.process_stack' in memory.get('sections', ['.process_stack']) %}
		"{{ key }}"
{% endfor %}
		HELP "Memory region for process stack in linker script"
		OUTPUT_NAME DISTORTOS_LD_PROCESS_STACK_REGION
		OUTPUT_TYPES BOOLEAN)

{% set context.counter = context.counter + 1 %}
distortosSetConfiguration(STRING
		distortos_Memory_regions_{{ '{:02d}'.format(context.counter) }}_Heap
{% for key, memory in dictionary['memories'].items() if memory is mapping and
	'on-chip-RAM' in memory['compatible'] and '.heap' in memory.get('sections', ['.heap']) %}
		"{{ key }}"
{% endfor %}
		HELP "Memory region for heap in linker script"
		OUTPUT_NAME DISTORTOS_LD_HEAP_REGION
		OUTPUT_TYPES BOOLEAN)
{% if 'NVIC' in dictionary and 'ARM,NVIC' in dictionary['NVIC']['compatible'] %}
{% for item in dictionary['NVIC']['chip-vectors'] if item %}
{% for subvector in item.get('subvectors', []) %}

if(ARCHITECTURE_NVIC_{{ subvector | upper }}_ENABLE)
	set(ARCHITECTURE_NVIC_{{ item['name'] | upper }}_ENABLE ON)
endif(ARCHITECTURE_NVIC_{{ subvector | upper }}_ENABLE)
{% endfor %}

if(ARCHITECTURE_NVIC_{{ item['name'] | upper }}_ENABLE)
	distortosSetFixedConfiguration(BOOLEAN
			DISTORTOS_ARCHITECTURE_NVIC_{{ item['name'] | upper }}_ENABLE
			ON)
endif(ARCHITECTURE_NVIC_{{ item['name'] | upper }}_ENABLE)
{% endfor %}
{% endif %}

include("${CMAKE_CURRENT_SOURCE_DIR}/source/architecture/ARM/ARMv6-M-ARMv7-M-ARMv8-M/distortos-sources.cmake")
